package com.woniuxy.kaer.system.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.kaer.commons.jwtUtil.JwtUtil;
import com.woniuxy.kaer.commons.util.Result;
import com.woniuxy.kaer.system.dto.ResourceDTO;
import com.woniuxy.kaer.system.dto.RoleResourceDTO;
import com.woniuxy.kaer.system.form.ResourceForm;
import com.woniuxy.kaer.system.model.Resources;
import com.woniuxy.kaer.system.param.ResourceParam;
import com.woniuxy.kaer.system.service.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sun
 * @since 2025年02月17日
 */
@Api(tags = "资源管理")
@RestController
@RequestMapping("/resource")
public class ResourceController {
    @Resource
    private ResourceService resourceService;
    @Resource
    private JwtUtil jwtUtil;



    // 查询该角色资源
    @ApiOperation(value = "查询自身的资源")
    @GetMapping("/getAllResources")
    public Result getAllResourcesById(@RequestHeader("token") String token) throws Exception {
        //通过token获取用户ID
        Integer userId = jwtUtil.getUserId(token);
        List<Resources> resources = resourceService.getAllResources(userId);
        return Result.succeed("查询所有资源成功", resources);
    }

    //查询所有资源
    @GetMapping("/findAllResources")
    public Result findAllResource() throws Exception {
        List<ResourceDTO> resources = resourceService.findAllResource();
        return Result.succeed("获取所有权限资源成功",resources);
    }
//    //新增资源
//    @ApiOperation(value = "新增资源")
//    @PostMapping("/addResource")
//
//    public Result addResource(@RequestBody ResourceForm form)throws Exception{
//        ResourceParam param = BeanUtil.toBean(form, ResourceParam.class);
//        resourceService.addResource(param);
//        return Result.succeed("新增资源成功",null);
//    }




}

